package cn.hs.service.impl;

import cn.hs.entity.*;
import cn.hs.mapper.ConsultMapper;
import cn.hs.mapper.UserMapper;
import cn.hs.mapper.UsermarkMapper;
import cn.hs.service.UsermarkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserMarkServiceImpl
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月24日 17:50
 * @Version 1.0
 */
@Service
public class UserMarkServiceImpl implements UsermarkService {
    @Autowired
    private UsermarkMapper usermarkMapper;
    @Autowired
    private ConsultMapper consultMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public PageInfo<Usermark> selctAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Usermark> usermarks = usermarkMapper.selectAll();
        //遍历文章集合
        for(Usermark usermark:usermarks){
            Integer userId1 = usermark.getUserId();
            User user = userMapper.selectById(userId1);
            Integer consultId = usermark.getConsultId();
            Consult consult = consultMapper.selectByPrimaryKey((long)consultId);
            usermark.setConsult(consult);
            usermark.setUser(user);
        }
        PageInfo<Usermark> pageInfo = new PageInfo<>(usermarks);
        return pageInfo;
    }

    @Override
    public Usermark selectById(Integer id) {
        return usermarkMapper.selectById(id);
    }

    @Override
    public int insert(Usermark usermark) {
        return usermarkMapper.insertAll(usermark);
    }

    @Override
    public int delete(Integer id) {
        return usermarkMapper.deleteById(id);
    }

    @Override
    public List<Usermark> selectByUserId(Integer userId) {
        return usermarkMapper.selectByUserId(userId);
    }

    @Override
    public List<Usermark> selectByConsultId(Integer consultId) {
        return usermarkMapper.selectByConsultId(consultId);
    }
}
